
const Topik = require('../model/topik');
const Record = require('../model/record')
const User = require('../model/user')

var mongoose = require('../provider/mongodb')

var methods = {
    put: async (uid, newObj) => {
        let one = await Topik.findById(newObj.id);
        if (one) {
            var saved = Object.assign({}, JSON.parse(JSON.stringify(one)), newObj);
            var record = Object.assign({}, saved)
            record.origincn = one.cn;
            record.originko = one.ko;
            record.originnote = one.note;
            record.uid = uid;
            record.tid = one._id;
            record._id = undefined;

            console.log('saved', saved)

            //const session = await mongoose.connection.startSession()

            let data = await Topik.findByIdAndUpdate(saved.id, saved)
            let msg = await new Record(record).save()

            //console.log(data, msg)
            return msg;
        }
    },
    add : async (uid, obj) => {

    }
}
module.exports = methods;